package com._520it.crm.web.controller;

import com._520it.crm.domain.CarModel;
import com._520it.crm.domain.ClientCar;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.service.ICarModelService;
import com._520it.crm.service.IClientCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/clientCar")
public class ClientCarController {
    @Autowired
    private IClientCarService clientCarService;
    @Autowired
    private ICarModelService carModelService;

    @RequestMapping("/selectByOrderBillId")
    @ResponseBody
    public Map<String,Object> selectByOrderBillId(Long orderBillId){
        Map<String,Object> clientCar = null;
        clientCar = clientCarService.selectByOrderBillId(orderBillId);
        return clientCar;
    }

    @RequestMapping("/reviseCar")
    @ResponseBody
    public AjaxResult reviseCar(Long orderBillId, ClientCar clientCar){
        AjaxResult result = null;
        try{
            clientCarService.updateByPrimaryKey(clientCar);
            result = new AjaxResult(true,"保存成功");
        }catch(Exception e){
            e.printStackTrace();
            result = new AjaxResult("保存失败,请联系管理员!");
        }
        return result;
    }

    @RequestMapping("alter1")
    @ResponseBody
    public AjaxResult alter1(ClientCar clientCar,String carModelIdD){
        AjaxResult result = null;
        try {
            CarModel carModel = carModelService.selectByCarModelName(carModelIdD);
            clientCar.setCarModel(carModel);
            clientCarService.updateById(clientCar);
            result = new AjaxResult(true,"更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult("更新失败");
        }
        return result;
    }
}
